import java.lang.reflect.Array;

import java.util.*;

public class Main {
    public static void main9(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int target=sc.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=sc.nextInt();
        }
        int left=0,right=n-1;
        Arrays.sort(ints);
        while ((left<=right)){
            int mid=(left+right)/2;
            if(ints[mid]>target){
                right=mid-1;
            }
            else if (ints[mid]<target) {
                left=mid+1;
            }
            else {
                System.out.println("下标："+mid);
            }
        }
    }
    public static void main7(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String[] strings=new String[n];
        sc.nextLine();
//        for(int i=0;i<=m;i++){
//            strings[0]+="0";
//        }
//        for(int i=0;i<=m;i++){
//            strings[n+1]+="0";
//        }
        for(int i=0;i<n;i++){
            strings[i]=sc.nextLine();
        }

        int sum=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                int det=1;
                if(i!=0){
                    if(strings[i-1].charAt(j)!=strings[i].charAt(j))
                    det=0;
                }
                if (i!=n-1&&det==1) {
                    if(strings[i+1].charAt(j)!=strings[i].charAt(j))
                    det=0;
                }
                if (j!=0&&det==1) {
                    if(strings[i].charAt(j-1)!=strings[i].charAt(j))
                    det=0;
                }
                 if (j!=m-1&&det==1) {
                    if(strings[i].charAt(j+1)!=strings[i].charAt(j))
                    det=0;
                }
                if(det==1)
                sum++;
            }
        }
        System.out.println(sum);
    }


    public static void main8(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        int sum1 = 0;
        while (sum1 < n+m) {
            int a=sc.nextInt();
            arrayList.add(a);
            sum1++;
        }
        for(int i=n;i<n+m;i++){
            int det=0;
            for(int j=0;j<n;j++){
                if(arrayList.get(i)==arrayList.get(j)){
                    if(i!=n+m-1)
                    System.out.print(j+1+" ");
                    else System.out.print(j+1);
                    det=1;
                    break;
                }
            }
            if(det==0) {
                if(i!=n+m-1)
                System.out.print(-1+" ");
                else System.out.print(-1);
            }
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int[] ints=new int[n];
        int[] ints2=new int[m];
        for(int i=0;i<n;i++){
                ints[i]=sc.nextInt();
        }
        for(int i=0;i<m;i++){
            ints2[i]=sc.nextInt();
        }
        for(int i=0;i<m;i++) {
            int target=ints2[i];
            int left=0,right=n-1;
            while ((left<=right)){
                int mid=left+(right-left)/2;
                if(ints[mid]>target)
                    right=mid-1;
                else if (ints[mid]<target)
                    left=mid+1;
                else if (mid!=0&&ints[mid-1]==target)
                    right=mid-1;
                else {
                    if(i!=m-1) System.out.print((mid+1)+" ");
                    else System.out.print((mid+1));
                    break;
                }
            }
            if(left>right){
                if(i!=m-1)
                    System.out.print(-1 + " ");
                else
                    System.out.print(-1);
            }
        }
    }

    static int equals(String str1,String str2){
        if(str2.length()!=str1.length())
            return str2.length()>str1.length()?1:0;
        else {
            int len=str1.length();
            for(int i=0;i<len;i++){
               if(str1.charAt(i)<str2.charAt(i)){
                   return 1;
               }
               else if (str1.charAt(i)>str2.charAt(i)) {
                   return 0;
               }
            }
            return 3;
        }
    }

    public static void main4(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<String> arrayList=new ArrayList<>();
        for(int i=0;i<n;i++){
            arrayList.add(sc.next());
        }
        String max=arrayList.get(0);
        for(int i=0;i<n-1;i++) {
            int det = equals(arrayList.get(i), arrayList.get(i + 1));
            if (det == 1){
                if(equals(max, arrayList.get(i + 1))==1) max=arrayList.get(i + 1);
            }
        }
        int sum=1;
        ArrayList<Integer> arrayList1=new ArrayList<>();
        for(int i=0;i<n;i++) {
            if(arrayList.get(i).equals(max)){
                sum++;
                arrayList1.add(i);
            }
        }
        for(int i=0;i<arrayList1.size();i++) {
            System.out.println(arrayList1.get(i)+1);
            System.out.println(max);
        }
    }
    public static void main3(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int k= sc.nextInt();
        int sum=n;
        while (n/k>0){
            sum+=n/k;
            n=n/k+n%k;
        }
        System.out.println(sum);
    }
    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
//        ArrayList<String> str=new ArrayList<>();
//        String str1;
//        while (sc.hasNextLine()){
//            str1=sc.next();
//            System.out.println(str1);
//            str.add(str1);
//        }
//
        String str = sc.nextLine();
        String[] strS = str.split(" ");

        for (int i = strS.length - 2; i >= 0; i--) {
            if (i != 0) System.out.print(strS[i] + " ");
            else System.out.print(strS[i]);
        }
    }


    public static void main1(String[] args) {
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        System.out.println((int)(A*0.2+B*0.3+C*0.5));
    }
}
